const fs = require('fs');
const path = require('path');

// 检查数据库文件是否存在
const dbPath = path.join(__dirname, 'database.db');
if (fs.existsSync(dbPath)) {
    console.log('数据库文件存在');
    const stats = fs.statSync(dbPath);
    console.log('文件大小:', stats.size, 'bytes');
} else {
    console.log('数据库文件不存在');
}

// 尝试连接数据库并查询数据
async function checkDatabase() {
    try {
        const database = require('./utils/database');
        await database.init();
        
        // 检查areas表
        const areas = await database.get('SELECT COUNT(*) as count FROM areas');
        console.log('Areas count:', areas.count);
        
        if (areas.count > 0) {
            const areaList = await database.all('SELECT * FROM areas LIMIT 5');
            console.log('Areas:', areaList);
        }
        
        // 检查repair_items表
        const items = await database.get('SELECT COUNT(*) as count FROM repair_items');
        console.log('Repair items count:', items.count);
        
        if (items.count > 0) {
            const itemList = await database.all('SELECT * FROM repair_items LIMIT 5');
            console.log('Repair items:', itemList);
        }
        
        await database.close();
        
        console.log('数据库检查完成');
    } catch (error) {
        console.error('检查数据库时出错:', error.message);
    }
}

checkDatabase();